import {
    toIsNewWindow,
} from "simpleRouter";
import config from "config"

export default {
    animation: config.routerAnimation == 'none' ? null : {
        includeNavtype: [`push`, `back`, `replace`],
        animationTime: 0.3,
        animationAppEl: (to, from) => {
            if (toIsNewWindow(to, from)) {
                return document.querySelector(`#app`)
            }
            if (to.meta && to?.meta?.animationEl && to?.meta?.navType === to.navType) {
                return document.querySelector(to.meta.animationEl)
            }
            return null
        },
        defaultAnimationType: (to) => {
            let animationType = `animate__slideInRight`
            if (config.routerAnimation == 'random') {
                const animationNode = [
                    `animate__slideInRight`,
                    `animate__bounceInRight`,
                    `animate__rotateInDownLeft`,
                    `animate__zoomInDown`,
                ]
                animationType = animationNode[
                    Number.parseInt(
                        Math.random() * animationNode.length,
                    )
                ]
            }
            if (to?.meta?.animation && to?.meta?.navType === to.navType) {
                animationType = to.meta.animation
            }
            return animationType
        },
        animationNodeMap: {
            animate__slideInRight: [
                // 前进
                [`animate__slideInRight`, `animate__slideOutLeft`],
                // 后退
                [`animate__slideInLeft`, `animate__slideOutRight`],
            ],
            animate__bounceInRight: [
                // 前进
                [`animate__bounceInRight`, `animate__bounceOutLeft`],
                // 后退
                [`animate__bounceInLeft`, `animate__bounceOutRight`],
            ],
            animate__rotateInDownLeft: [
                // 前进
                [`animate__rotateInDownLeft`, `animate__rotateOutDownLeft`],
                // 后退
                [`animate__rotateInDownRight`, `animate__rotateOutDownRight`],
            ],
            animate__zoomInDown: [
                // 前进
                [`animate__zoomInDown`, `animate__zoomOutDown`],
                // 后退
                [`animate__zoomInUp`, `animate__zoomOutDown`],
            ],
            // 给路由定义的动画
            child_router_animate: [
                // 前进
                [`animate__slideInUp`],
            ],
        },
    },
}